package com.junzhiit.nengji.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.junzhiit.nengji.bo.MemberCardHistoryBO;
import com.junzhiit.nengji.cms.service.MemberCardHistoryService;
import com.junzhiit.nengji.cms.web.util.ViewObjectUtil;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.MemberCardHistoryVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.SystemUserSessionVO;
import com.junzhiit.nengji.dao.ChainDAO;
import com.junzhiit.nengji.dao.MemberCardHistoryDAO;
import com.junzhiit.nengji.dao.ShopDAO;
import com.junzhiit.nengji.dao.cache.SystemUserCacheDAO;
import com.junzhiit.nengji.dao.util.DIYKey;

@Service
public class MemberCardHistoryServiceImpl implements MemberCardHistoryService {

	@Autowired
	MemberCardHistoryDAO memberCardHistoryDAO;
	
	@Autowired
	SystemUserCacheDAO systemUserCacheDAO;
	
	@Autowired
	ShopDAO shopDAO;
	
	@Autowired
	ChainDAO chainDAO;
	
	@Override
	public Map<String, Object> queryForList(DataTablesParamVO dtp, MemberCardHistoryVO mchv) {
		SystemUserSessionVO sessionVO=systemUserCacheDAO.
				getHash(DIYKey.getSessionHashKey(mchv.getSessionId()), SystemUserSessionVO.class);
		MemberCardHistoryBO mchb=new MemberCardHistoryBO();
		BeanUtils.copyProperties(mchv, mchb);
		mchb.setCsId(sessionVO.getSystemId());
		List<MemberCardHistoryBO> mchbList=memberCardHistoryDAO.queryForList(mchb, dtp.getStart(), dtp.getLength());
		int total=memberCardHistoryDAO.queryForTotal(mchb);
		return ViewObjectUtil.dataTables(mchbList, dtp.getDraw(), total);
	}

	@Override
	public ResultVO findForTotal(String sessionId) {
		ResultVO result=new ResultVO();
		SystemUserSessionVO sessionVO=systemUserCacheDAO.
				getHash(DIYKey.getSessionHashKey(sessionId), SystemUserSessionVO.class);
		MemberCardHistoryBO mchbo= memberCardHistoryDAO.findForTotal(sessionVO.getSystemId());
		result.setData(mchbo);;
		return result;
	}

}
